<?php
namespace app\admin\controller;
use app\admin\controller\Common;

class Column extends Common
{
    public function index()
    {	
    	$list = db('column')->select();
    	$this->assign('list',$list);
	    return view();
    }

    public function add()
    {
    	if(request()->isPost()){
    		$res = db('column')->insert($_POST);
    		if($res){
    			$this->success('添加成功');
    		}else{
    			$this->error('添加失败');
    		}
    	}
    }

    public function del($id)
    {
    	$res = db('column')->where('id',$id)->delete();
    	if ($res) {
    		$this->success('删除成功');
    	}else{
    		$this->error('删除失败');
    	}
    }

    public function edit($id)
    {
        if(request()->isPost()){
            $res = db('column')->where('id',$id)->update($_POST);
            if ($res) {
                $this->success('修改成功','Column/index');
            }else{
                $this->error('修改失败');
            }
        }
        $list = db('column')->where('id',$id)->find();
        $this->assign('list',$list);
    	return view();
    }

}
